unit Conf_SequenciaDocumentos;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, SqlExpr, Provider, DB, DBClient, DBLocal, DBLocalS, Grids,
  DBGrids, StdCtrls, Buttons, Mask, DBCtrls;

type
  TFrmConfSeqDocumentos = class(TForm)
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    SQLC_SequenciaDocumentos: TSQLClientDataSet;
    Label1: TLabel;
    edtEmpresa: TEdit;
    btnEmpresa: TBitBtn;
    stEmpresa: TStaticText;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    procedure DBEditEmpresa_IDFExit(Sender: TObject);
    procedure edtEmpresaExit(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FrmConfSeqDocumentos: TFrmConfSeqDocumentos;

implementation

uses DmGeral;

{$R *.dfm}

procedure TFrmConfSeqDocumentos.DBEditEmpresa_IDFExit(Sender: TObject);
begin
  if Length(Trim(edtEmpresa.Text)) > 0 then
     if (ValidaCampo( edtEmpresa, 'P','select * from EMPRESAS where EMP_CODIGO=' +
                      QuotedStr(edtEmpresa.Text)+';') ) and (not DtMGeral.Sqlq_geral.IsEmpty) then begin
       stEmpresa.Caption := DtMGeral.sqlq_geral.FieldByName('EMP_FANTAS').AsString;
       SQLC_SequenciaDocumentos.Close;
       SQLC_SequenciaDocumentos.Params[0].AsString := edtEmpresa.Text;
       SQLC_SequenciaDocumentos.Open;
     end;
  if Trim( edtEmpresa.Text ) = '' then
    btnEmpresa.SetFocus;
end;

procedure TFrmConfSeqDocumentos.edtEmpresaExit(Sender: TObject);
begin
  stEmpresa.Caption := '';
  if Length(Trim(edtEmpresa.Text)) > 0 then
     if (ValidaCampo( edtEmpresa, 'P','select * from EMPRESAS where EMP_CODIGO=' +
                      QuotedStr(edtEmpresa.Text)+';') ) and (not DtMGeral.Sqlq_geral.IsEmpty) then begin
       stEmpresa.Caption := DtMGeral.sqlq_geral.FieldByName('EMP_FANTAS').AsString;
       SQLC_SequenciaDocumentos.Close;
       SQLC_SequenciaDocumentos.Params[0].AsString := edtEmpresa.Text;
       SQLC_SequenciaDocumentos.Open;
     end;
  if Trim(edtEmpresa.Text) = '' then
    btnEmpresa.SetFocus;
end;

procedure TFrmConfSeqDocumentos.BitBtn1Click(Sender: TObject);
begin
  SQLC_SequenciaDocumentos.ApplyUpdates(0);
end;

procedure TFrmConfSeqDocumentos.BitBtn2Click(Sender: TObject);
begin
  SQLC_SequenciaDocumentos.CancelUpdates;
end;

end.
